home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / queue.zip / QUEUE / QCLIENT.C < prev    next >
C/C++ Source or Header  |  1992-10-10  |  3KB  |  115 lines

  1. /************************************************************************\
  2. * The enclosed files, "the software," is provided by 
  3. * Microsoft Corporation "as is" without warranty of any kind. 
  4. * MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, 
  5. * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY 
  6. * AND FITNESS FOR A PARTICULAR PURPOSE.  You assume all risks of 
  7. * using the software.
  8. * The software is Copyright (c) 1992 Microsoft Corporation.
  9. * Original Author: John M. Hall, Microsoft SDE  9/1/92
  10. *
  11. * You are granted the right to freely distribute this software.
  12. * You are granted the right to make changes provided this comment block
  13. * is retained without modification and you acknowledge the changes.
  14. \************************************************************************/
  15. #define DEBUG
  16. #include <stdio.h>
  17. #include <assert.h>
  18. #include <windows.h>
  19. #include <string.h>
  20. #include <queue.h>
  21. #include <shrmem.h>
  22. #include <myopt.h>
  23.  
  24. #define QUEUE_NAME "\\queues\\test"
  25.  
  26. #define TEST_MSGS     5
  27. #define TEST_DELAY  400
  28.  
  29. struct _write_test {
  30.     DWORD  dwEventCode;
  31.     DWORD  dwPriority;
  32.     LPTSTR lptstr;
  33. } test[TEST_MSGS] =
  34.     {
  35.      0,  0, "Terminate Processing",
  36.     11,  1, "First message sent",
  37.     12, 10, "Second message sent",
  38.     13,  5, "Third test msg",
  39.     14,  8, "Fourth"
  40.     };
  41.  
  42. void do_it(HQUEUE hq, int ii)
  43. {
  44.     DWORD   dwShrHandle;
  45.     LPTSTR  lptstr;
  46.  
  47.     dwShrHandle = ShrAlloc( 1000, 0);
  48.     lptstr = (LPTSTR) ShrLock(dwShrHandle);
  49.     strcpy( lptstr, test[ii].lptstr);
  50.     ShrUnlock(dwShrHandle);
  51.     printf( "Writing %d %d %d\n", test[ii].dwEventCode,
  52.             dwShrHandle, test[ii].dwPriority);
  53.     WriteQueue(hq, test[ii].dwEventCode, dwShrHandle, test[ii].dwPriority);
  54.     Sleep(TEST_DELAY);
  55.  
  56. }
  57.  
  58. main(int argc, char *argv[])
  59. {
  60.     HQUEUE  hq;
  61.     DWORD   dwErr;
  62.     DWORD   dwOwner;
  63.     int     ii;
  64.     HANDLE  hClient;
  65.     BOOL    bWait = FALSE;
  66.     int     iFlag;
  67.  
  68.  
  69.     while (iFlag = my_getopt( argc, argv, "w"))
  70.         {
  71.         switch(iFlag)
  72.             {
  73.             case 'w':
  74.                 bWait = TRUE;
  75.                 break;
  76.             default:
  77.                 printf( "Unidentified flag %c\n", (char) iFlag);
  78.                 break;
  79.             }
  80.         }
  81.  
  82.  
  83.  
  84.     if (bWait)
  85.         hClient = CreateEvent( NULL, TRUE, FALSE, "ClientSaysGo");
  86.  
  87.     dwErr = OpenQueue( &dwOwner, &hq, QUEUE_NAME);
  88.  
  89.     if (dwErr != 0)
  90.         {
  91.         printf( "CreateQueue Failed\n");
  92.         return(-1);
  93.         }
  94.  
  95.     printf( "Queue owner is %d\n", dwOwner);
  96.  
  97.  
  98.     for (ii = 1; ii < TEST_MSGS; ii++)
  99.         {
  100.         do_it(hq, ii);
  101.         }
  102.  
  103.     if (bWait)
  104.         SetEvent(hClient);
  105.  
  106.     do_it(hq, 0);
  107.  
  108.     printf( "Client exiting\n");
  109.     CloseQueue(hq);
  110.  
  111.     return(0);
  112. }
  113.